*****************************************************************
*																*
*				Title: regressions_cotton_app		 	 	   	*		
*															    *
*****************************************************************

/*  ================================  NOTES  ================================

+ PURPSOSE:
	
	In this do-file we run regressions for the cotton sector for the appendix and output them
 
		
+ Inputs:

		* 1. final/panel_cotton.dta


==============================  TOP MATTER ==============================*/



	*set paths
	global proc_data "`pdir'/data"
	global output "`pdir'/outputs/appendix"

********************************** END HEADER ********************************

use "$proc_data/panel_cotton.dta", clear

*************************************************************************
********************	 	 TABLES APPENDIX	 	 ********************	
*************************************************************************



******	Table A.2. Panel A Summary Statistics: Cotton Spinning Plants    
******************************************************************************

*Some rounding is applied by hand after generating the table, as the frmttable command is not flexible in adjusting digits after the comma

* make empty matrix
mat table_a2 = J(14,10,.)

** Panel A, LHS, Around 1800:

local counter = 1

foreach x of varlist logYoverL_real L_total firm_age exit_1806 average_quality total_machines jenny_jea jenny_fc jenny_mj spindles K_over_L {
	
	
	sum `x' if year==1806, d
	
	mat table_a2[`counter',1] = r(N)
	mat table_a2[`counter',2] = r(mean)
	mat table_a2[`counter',3] = r(sd)
	mat table_a2[`counter',4] = r(min)
	mat table_a2[`counter',5] = r(max)
	
	local counter = `counter' + 1
	matlist table_a2
} 

** Panel A RHS: starts in column 6

local counter = 1

foreach x of varlist logYoverL_real L_total spindles K_over_L dummy_water_mill dummy_steam_mill dummy_other_mill {
	
	
	sum `x' if year==1840, d
	
	mat table_a2[`counter',6] = r(N)
	mat table_a2[`counter',7] = r(mean)
	mat table_a2[`counter',8] = r(sd)
	mat table_a2[`counter',9] = r(min)
	mat table_a2[`counter',10] = r(max)
	
	if `counter' == 2 {
		local counter = 10
	}
	else {
		local counter = `counter' + 1
	}
	matlist table_a2
} 

matlist table_a2


frmttable using "$output/Tables/Table_A2A.tex", statmat(table_a2) replace ///
	landscape tex fragment ///
	rtitles("Log (output per worker)" \ "Number of workers" ///
	\ "Plant Age" \ "Exit dummy" \ "Avg. quality of yarn" \ ///
	"Total num. of machines" \ "Num. spinning jennies" \ "Num. water-frames" /// 
	\ "Num. of spinning-mules" \ "Spindles" \ "Spindles per worker" ///
	\ "Water power" \ "Steam power" \ "Other power") ///
	sdec(0 , 2 , 2 , 2 , 2,0,2) 
			
** More cleaning for the tex table 
preserve 
	clear
	set obs 1
	local tex "$output/Tables/Table_A2A.tex"
	local tex2 "$output/Tables/Table_A2A.tex"

	generate strL s = fileread("`tex'") if fileexists("`tex'")
	assert filereaderror(s)==0

	*removing the beggining and end to only insert the numbers and rows in stata

	replace s = ustrregexrf(s,"(?s).*Log","Log")

	replace s = ustrregexrf(s,"\\noalign.*(?s)","")
	replace s = ustrregexrf(s,"\\end.*(?s)","")

	gen byte fw = filewrite("`tex2'",s,1)
restore

******	Table A.2. Panel B Summary Statistics: Cotton Spinning Plants in 1806   
******************************************************************************

* make empty matrix
mat table_a2_b = J(9,10,.)

**Panel B. LHS
local counter = 1

foreach x of varlist highsflow closecoal share_forest lnoutputdensity_commune lnma_FRA lnma dept_port_dummy lnconscripts_pc near_battles10 {
	
	
	sum `x' if year==1806
	
	mat table_a2_b[`counter',1] = r(N)
	mat table_a2_b[`counter',2] = r(mean)
	mat table_a2_b[`counter',3] = r(sd)
	mat table_a2_b[`counter',4] = r(min)
	mat table_a2_b[`counter',5] = r(max)
	
	local counter = `counter' + 1
// 	matlist table_a2_b
} 

** Panel B RHS: starts in column 6

local counter = 1

foreach x of varlist highsflow closecoal share_forest lnoutputdensity_commune lnma_FRA lnma dept_port_dummy lnconscripts_pc near_battles10 {
	
	
	sum `x' if year==1840
	
	mat table_a2_b[`counter',6] = r(N)
	mat table_a2_b[`counter',7] = r(mean)
	mat table_a2_b[`counter',8] = r(sd)
	mat table_a2_b[`counter',9] = r(min)
	mat table_a2_b[`counter',10] = r(max)
	
	local counter = `counter' + 1
// 	matlist table_a2_b
} 

matlist table_a2_b


frmttable using "$output/Tables/Table_A2B.tex", statmat(table_a2_b) replace ///
	landscape tex fragment ///
	rtitles("Access to high streamflow" \ "Production density" \ "Share of forest area" ///
	\ "Production density" \ "Market access, France" \ "Market access, Europe" ///
	\ "Access to overseas market" \ ///
	"log(conscripts pc)" \ "Near Battles") ///
	sdec(0 , 2 , 2 , 2 , 2 , 0, 2) 
	
preserve 
	clear
	set obs 1
	local tex "$output/Tables/Table_A2B.tex"
	local tex2 "$output/Tables/Table_A2B.tex"

	generate strL s = fileread("`tex'") if fileexists("`tex'")
	assert filereaderror(s)==0

	*removing the beggining and end to only insert the numbers and rows in stata

	replace s = ustrregexrf(s,"(?s).*Access to high","Access to high")

	replace s = ustrregexrf(s,"\\noalign.*(?s)","")
	replace s = ustrregexrf(s,"\\end.*(?s)","")

	gen byte fw = filewrite("`tex2'",s,1)
restore	 
     

******	Table A.2. Panel C Summary Statistics: Cotton Spinning Plants  *******
******************************************************************************

* make empty matrix
mat table_a2_c = J(4,10,.)

**Panel C. LHS
local counter = 1

foreach x of varlist distance_above_p90_1800 distance_above_p90_metal_1800 distance_above_p90_paper_1800 distance_london {
	
	
	sum `x' if year==1806
	
	mat table_a2_c[`counter',1] = r(N)
	mat table_a2_c[`counter',2] = r(mean)
	mat table_a2_c[`counter',3] = r(sd)
	mat table_a2_c[`counter',4] = r(min)
	mat table_a2_c[`counter',5] = r(max)
	
	local counter = `counter' + 1
// 	matlist table_a2_b
} 

** Panel B RHS: starts in column 6

local counter = 1

foreach x of varlist distance_above_p90_1840 distance_london {
	
	
	sum `x' if year==1840
	
	mat table_a2_c[`counter',6] = r(N)
	mat table_a2_c[`counter',7] = r(mean)
	mat table_a2_c[`counter',8] = r(sd)
	mat table_a2_c[`counter',9] = r(min)
	mat table_a2_c[`counter',10] = r(max)
	
	if `counter' == 1 {
		local counter = 4
	}
	else {
		local counter = `counter' + 1
	}
	
// 	matlist table_a2_c
} 

matlist table_a2_c


frmttable using "$output/Tables/Table_A2C.tex", statmat(table_a2_c) replace ///
	landscape tex fragment ///
	rtitles("Dist to p90" \ "Dist to p90 metal (1800)" \ "Dist to p90 paper (1800)" ///
	\ "Dist to London") ///
	sdec(0 , 2 , 2 , 2 , 2 , 0, 2) 
	
preserve 
	clear
	set obs 1
	local tex "$output/Tables/Table_A2C.tex"
	local tex2 "$output/Tables/Table_A2C.tex"

	generate strL s = fileread("`tex'") if fileexists("`tex'")
	assert filereaderror(s)==0

	*removing the beggining and end to only insert the numbers and rows in stata

	replace s = ustrregexrf(s,"(?s).*smallskip\}Dist","Dist")

	replace s = ustrregexrf(s,"\\noalign.*(?s)","")
	replace s = ustrregexrf(s,"\\end.*(?s)","")

	gen byte fw = filewrite("`tex2'",s,1)
restore	 



************	Table A.5 (Panel A) *************************************************
*** Annual Productivity Growth (in %) at Different Quantiles of the Distribution	
*** Same as Table 1A

estimates clear
quietly{
	eststo: xi:reg logYoverL_real_pa i.year,  vce(robust) 
local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(90) vce(robust)
}
estout using "$output/Tables/Table_A5A.tex", replace label ///
	drop(_cons) order($show ) rename (_Iyear_1840 "Spinning \ (1806-1840)") ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") ///
	end("& `N_obs'" "\\[-0.15cm]")  varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) ///
	starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) ///
	collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table"
	

*****Table A.5 (Panel B): ******************************************************
***Alternative Productivity Measures in Cotton Spinning 

***Using prices not quality-adjusted
estimates clear
quietly{
	eststo: xi:reg  logYmeanoverL_real_pa i.year,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg  logYmeanoverL_real_pa i.year, quantile(10) vce(robust)
	eststo: xi:qreg  logYmeanoverL_real_pa i.year, quantile(25) vce(robust)
	eststo: xi:qreg  logYmeanoverL_real_pa i.year, quantile(50) vce(robust)
	eststo: xi:qreg  logYmeanoverL_real_pa i.year, quantile(75) vce(robust)
	eststo: xi:qreg  logYmeanoverL_real_pa i.year, quantile(90) vce(robust)
}
estout using "$output/Tables/Table_A5B.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 
*redundancy in reported number of observations in the last column is fixed by hand after generating the table"
	
	
*****	Table A.5 (Panel C): ***************************************************
*** Alternative Productivity Measures in Cotton Spinning    


***Using TFP 

preserve	

*** Get residual for Y on L and K by year

* 1806
reg logPY_real logL_total logK if year == 1806, r
local constant1806 =  _b[_cons]
predict TFP1806 if year ==1806, res
gen TFP1806_inclmean = TFP1806 + `constant1806'
replace TFP1806_inclmean = . if year == 1840


* 1840
reg logPY_real logL_total logK if year == 1840, r
local constant1840 =  _b[_cons]
predict TFP1840 if year == 1840, res
gen TFP1840_inclmean = TFP1840 + `constant1840'
replace TFP1840_inclmean = . if year == 1806

* TFP (incl constant for scaling across years)
gen TFP_inclmean = TFP1806_inclmean if year == 1806
replace TFP_inclmean = TFP1840_inclmean if year == 1840

	
estimates clear	
quietly{
eststo: xi:reg TFP_inclmean i.year,  vce(robust)		
local N_obs = e(N)
eststo: xi:qreg TFP_inclmean i.year, quantile(10) vce(robust)
eststo: xi:qreg TFP_inclmean i.year, quantile(25) vce(robust)
eststo: xi:qreg TFP_inclmean i.year, quantile(50) vce(robust)
eststo: xi:qreg TFP_inclmean i.year, quantile(75) vce(robust)
eststo: xi:qreg TFP_inclmean i.year, quantile(90) vce(robust)	
}
estout using "$output/Tables/Table_A5C.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table"
		
restore	




***	Table A.17: Productivity and the Use of Steam Power in Cotton Spinning (1840)    
**********************************************************************************
	
preserve
label var dummy_steam_mill "Steam power"
label var dummy_water_mill "Water power"
label var dummy_other_mill "Other power"
	
	estimates clear
quietly{
	eststo: reg logYoverL_real dummy_steam_mill , r
	eststo: reg logYoverL_real dummy_water_mill, r	
	eststo: reg logYoverL_real dummy_steam_mill dummy_water_mill, r
	eststo: reg logYoverL_real dummy_steam_mill dummy_other_mill , r
}
estout using "$output/Tables/Table_A17.tex", replace label drop (_cons) order($show ) ///
 prefoot("\hline") stats(r2 N, layout(@ "\multicolumn{1}{c}{@}") fmt(2 %9.0g) labels("R$^2$" "N")) ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.1cm] ") end("\\[-0.15cm]") varlabels(, end("\addlinespace[0.2cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 

restore
	
	

************	Table A.18: Productivity of Exiting Relative to Surviving Plants (column 1)	 	***********
*** needs to be manually put together for one table in the paper	
	
estimates clear
quietly {

	reg logYoverL_real exit_1806 if year == 1806 , r
	
	}
	
estout using "$output/Tables/Table_A18_cotton.tex", replace label drop (_cons) ///
rename (exit_1806 "Exit dummy") ///
 prefoot("\hline") stats( N, layout(@ "\multicolumn{1}{c}{@}") fmt(%9.0g) labels("N")) ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.1cm] ") end("\\[-0.15cm]") varlabels(, end("\addlinespace[0.2cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(Cotton) 	 	
	
	
	
	
*********	Table A.19:       ***********************************************
*** Cotton Spinning in 1840: Productivity and Plants' Age Profile
	
preserve
label var dummy_steam_mill "Steam power"
label var dummy_water_mill "Water power"
label var dummy_other_mill "Other power"

estimates clear
quietly{
	eststo: reg logYoverL_real entrant_1840  if year == 1840, r
	eststo: reg logYoverL_real entrant_1840 dummy_water_mill  if year == 1840, r
	eststo: reg logYoverL_real entrant_1840 dummy_steam_mill  if year == 1840, r
	eststo: reg logYoverL_real entrant_1840 dummy_other_mill  if year == 1840, r
	eststo: reg logYoverL_real entrant_1840 logL_total  if year == 1840, r
	}
estout using "$output/Tables/Table_A19.tex", replace label drop (_cons) order($show ) ///
 prefoot("\hline") stats(r2 N, layout(@ "\multicolumn{1}{c}{@}") fmt(2 %9.0g) labels("R$^2$" "N")) ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.1cm] ") end("\\[-0.15cm]") varlabels(, end("\addlinespace[0.2cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 
	
restore
	
	
	
	
****	Table A.22 (Panel A): **************************************************
******Productivity Growth by Quantiles – Controlling for Region FE   

estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year i.id_region,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year i.id_region, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year i.id_region, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year i.id_region, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year i.id_region, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year i.id_region, quantile(90) vce(robust)
}

estout using "$output/Tables/Table_A22A.tex", replace label drop( _Iid_region_*) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none)	 ///
	indicate("Region FE=_cons", labels("\multicolumn{1}{c}{\checkmark}" "\multicolumn{1}{c}{ }"))			
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
	
	
	
	
************	Table A.23 (Panel A):    ***************************************
**** Productivity Growth by Quantiles – Controlling for Market Access, France 

estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year lnma_FRA,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year lnma_FRA, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma_FRA, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma_FRA, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma_FRA, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma_FRA, quantile(90) vce(robust)
}

estout using "$output/Tables/Table_A23A.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
		
		
************	Table A.23 (Panel B):  ***************************************
***  Productivity Growth by Quantiles – Controlling for Market Access, Europe

estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year lnma,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year lnma, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year lnma, quantile(90) vce(robust)
}

estout using "$output/Tables/Table_A23B.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	

	
************	Table A.23. (Panel C): ***************************************
*** Productivity Growth by Quantiles – Controlling for Coastal departments    


estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year dept_port_dummy,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year dept_port_dummy, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year dept_port_dummy, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year dept_port_dummy, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year dept_port_dummy, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year dept_port_dummy, quantile(90) vce(robust)
}

estout using "$output/Tables/Table_A23C.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
		
		

		
************	Table A.24:    ************	**********************************
*** Plant Survival Rates in Cotton Spinning in the North and South of France  

matrix surv_cotton = J(5, 2, .)

summ latitude if year == 1806, d
local lat `r(p50)'

**** North
*Survival rate

sum survival if year == 1806 & survival == 1 & latitude > `lat'   /* n = 13 */
local n_survival_num `r(N)'
sum survival if year == 1806 & latitude > `lat' /* n = 192 */
local n_survival_den `r(N)'

local div_nort_1 = `n_survival_num'/`n_survival_den'*100 /* n = 6.8% */

mat surv_cotton[1, 1] = `div_nort_1'
mat surv_cotton[2, 1] = `n_survival_den'
 
*Restricted sample survival
sum survival if year == 1806 & survival_type_2 == 1 & latitude > `lat' /* n = 8 */
local n_res_survival_num `r(N)'
sum survival if year == 1806 & single_plant == 1 & latitude > `lat'  /* n = 36 */
local n_res_survival_den `r(N)'

local div_nort_2 = `n_res_survival_num'/`n_res_survival_den'*100 /* 22% */

mat surv_cotton[4, 1] = `div_nort_2'
mat surv_cotton[5, 1] = `n_res_survival_den'


**** South
*Survival rate
sum survival if year == 1806 & survival == 1 & latitude < `lat'   /* n = 4 */
local s_survival_num `r(N)'
sum survival if year == 1806 & latitude < `lat'  /* n = 148 */
local s_survival_den `r(N)'

local div_south_1 = `s_survival_num'/`s_survival_den'*100 /* n = 2.7% */

mat surv_cotton[1, 2] = `div_south_1'
mat surv_cotton[2, 2] = `s_survival_den' 
 
*Restricted sample survival
sum survival if year == 1806 & survival_type_2 == 1 & latitude < `lat' /* n = 3 */
local s_res_survival_num `r(N)'
sum survival if year == 1806 & single_plant == 1 & latitude < `lat'  /* n = 51 */
local s_res_survival_den `r(N)'

local div_south_2 = `s_res_survival_num'/`s_res_survival_den'*100 /* n = 5.9% */

mat surv_cotton[4, 2] = `div_south_2'
mat surv_cotton[5, 2] = `s_res_survival_den'

frmttable using "$output/Tables/Table_A24.tex", statmat(surv_cotton) replace ///
	landscape tex fragment ///
	rtitles("Survival rate" \ "Number of plants" ///
	\ "" \ "Restricted sample survival rate" \ "Number of plants") ///
	sdec(1 \ 0 \ 0 \ 1 \ 0) 
	
** More cleaning for the tex table 
preserve 
	clear
	set obs 1
	local tex "$output/Tables/Table_A24.tex"
	local tex2 "$output/Tables/Table_A24.tex"
	
	generate strL s = fileread("`tex'") if fileexists("`tex'")
	assert filereaderror(s)==0

	*removing the beggining and end to only insert the numbers and rows in stata

	replace s = ustrregexrf(s,"(?s).*Survival","Survival")

	replace s = ustrregexrf(s,"\\noalign.*(?s)","")
	replace s = ustrregexrf(s,"\\end.*(?s)","")
	
	replace s = ustrregexra(s,"& 6.8 & 2.7\\","& 6.8\\% & 2.7\\%\\")
	replace s = ustrregexra(s,"& 22.2 & 5.9\\","& 22.2\\% & 5.9\\%\\")

	gen byte fw = filewrite("`tex2'",s,1)
restore




************	Table A.25 Cols 1 and 4:    ***********************************	

** Correlation between logY/L and conscripts/capita *****
*** Table naeeds to be manually put together

estimates clear 
	eststo: reg logYoverL_real lnconscripts_pc if year==1806, cl(id_region)
	eststo: reg logYoverL_real lnconscripts_pc if year==1840, cl(id_region)

estout using "$output/Tables/Table_A25_cotton.tex", replace label drop(_cons) order($show ) ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	stats(r2 N, layout(@ "\multicolumn{1}{c}{@}") fmt(2 %9.0g) labels("R$^2$" "N")) ///	
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 	

	
	
	
************	Table A.26 Col 1     ******************************************	
** Correlation between logY/L and battles within 10k in 1840	
*** Table naeeds to be manually put together
	
estimates clear	
	eststo: reg logYoverL_real near_battles10 if year==1840, vce(robust)	
	
	estout using "$output/Tables/Table_A26_cotton.tex", replace label drop(_cons) order($show ) ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	stats(r2 N, layout(@ "\multicolumn{1}{c}{@}") fmt(2 %9.0g) labels("R$^2$" "N")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 
	
	
	
	
************	Table A.27 (Panel A): ******************************************
*** Productivity Growth by Quantiles – Plants with at Least 10 Workers   

estimates clear
quietly{
	eststo: xi:reg logYoverL_real_pa i.year  if L_total>=10,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year  if L_total>=10, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year  if L_total>=10, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year  if L_total>=10, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year  if L_total>=10, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year  if L_total>=10, quantile(90) vce(robust)
}
estout using "$output/Tables/Table_A27A.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
	
	
	
	
************	Table A.28 : ******************************************
*** Productivity by Quantiles – Excluding Plants that used Spinning Jennies    
	
estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year if spindle_lowtech!=1,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year if spindle_lowtech!=1, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year if spindle_lowtech!=1, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year if spindle_lowtech!=1, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year if spindle_lowtech!=1, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year if spindle_lowtech!=1, quantile(90) vce(robust)
}
	estout using "$output/Tables/Table_A28.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.1cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.15cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
	

	
	
************	Table A.29 (Panel A):  ******************************************
*** Productivity by Quantiles – Controlling for Number of Workers    	

estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year logL_total,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year logL_total, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logL_total, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logL_total, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logL_total, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logL_total, quantile(90) vce(robust)
}

estout using "$output/Tables/Table_A29A.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
	
	
	
	
************	Table A.30: **********************************************	
*** Spinning Productivity by Quantiles: Controlling for Capital Deepening    

estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year logK_over_L,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year logK_over_L, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logK_over_L, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logK_over_L, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logK_over_L, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year logK_over_L, quantile(90) vce(robust)
}

estout using "$output/Tables/Table_A30.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
		
	
	
	
************	Table A.31: *****************
*** Annual Productivity Growth (in %) at Different Parts of the Distribution
*** Using prices not quality-adjusted and controlling for number of workers    ************	

estimates clear	
quietly{
	eststo: xi:reg logYmeanoverL_real_pa i.year logL_total,  vce(robust)	
	local N_obs = e(N)
	eststo: xi:qreg logYmeanoverL_real_pa i.year logL_total, quantile(10) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year logL_total, quantile(25) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year logL_total, quantile(50) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year logL_total, quantile(75) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year logL_total, quantile(90) vce(robust)
}
estout using "$output/Tables/Table_A31.tex", replace label drop(_cons) order($show ) ///
	rename (_Iyear_1840 "Spinning \ (1806-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 		
*redundancy in reported number of observations in the last column is fixed by hand after generating the table	
		
	
		
			

*******************************************************************
******************	 	 FIGURES APPENDIX	 	 ******************	
*******************************************************************


************	Figure A.19: Spinning: Productivity growth in the `North' and `South' of France	 	***********

*** find median latitude amongst the sample of 1806 plants
summ latitude if year == 1806, d
local lat `r(p50)'

**North
twoway (kdensity logYoverL_real if year == 1806 & latitude > `lat', bwidth(0.2) lcolor(gs6) lpattern(dash) lwidth(thick)) ///
 (kdensity logYoverL_real if year == 1840 & latitude > `lat', bwidth(0.2) lcolor(navy) lpattern(solid) lwidth(thick)), ///
 ytitle(Kernel density, size(large)) xtitle(ln(Output per worker), size(large)) xscale(range(2 10)) xlabel(2(2)10, labsize(medlarge)) ylabel(, labsize(medlarge)) ///
 legend(order(1 "1806" 2 "1840") position(9) ring(0) cols(1) size(large))  scheme(s1color)

graph export "$output/Figures/Figure_A19A.eps", replace
graph export "$output/Figures/Figure_A19A.pdf", replace


**South
twoway (kdensity logYoverL_real if year == 1806 & latitude < `lat', bwidth(0.2) lcolor(gs6) lpattern(dash) lwidth(thick)) ///
 (kdensity logYoverL_real if year == 1840 & latitude < `lat', bwidth(0.2) lcolor(navy) lpattern(solid) lwidth(thick)), ///
 ytitle(Kernel density, size(large)) xtitle(ln(Output per worker), size(large)) xscale(range(2 10)) xlabel(2(2)10, labsize(medlarge)) ylabel(, labsize(medlarge)) ///
 legend(order(1 "1806" 2 "1840") position(9) ring(0) cols(1) size(large))  scheme(s1color)

graph export "$output/Figures/Figure_A19B.eps", replace
graph export "$output/Figures/Figure_A19B.pdf", replace




	





